<?php
namespace Rac\Controller;
use Think\Controller;
class GroupController extends BaseController {
	
	
    public function index(){ 
		
    	
		$data = D('AuthGroup')->getAuthGroupList();
    	
		$this->assign('data', $data);
    	$this->display();
    }
    
    
    public function rules_form() {
    	$group_id = I('post.group_id');
    	$rules = I('post.rules');
    	
    	D('AuthGroup')->setGroupRules($group_id, $rules);
    	echo 1;die;
    }
    
	public function rules() {
		$id = I('get.id');
		
		$group = D('AuthGroup')->getGroupById($id);
		
		$authRuleList = D('AuthRule')->getAuthRuleList();
		
		$rules =  explode(',', $group['rules']);
		foreach ($authRuleList as $key=>$value) {
			foreach ($value['child'] as $k=>$v) {
				if (in_array($v['id'], $rules)) {
					$authRuleList[$key]['child'][$k]['flag'] = 1;
				}
			}
		}
		
		
		
		$this->assign('rules', explode(',', $rules));
		$this->assign('group', $group);
		$this->assign('authRuleList', $authRuleList);
		$this->display();
	}
    
    
    public function add_form() {
    	$flag = D('AuthGroup')->addAuthGroup(I('post.title'), I('post.des'));
    	$data = array('flag'=>0, 'msg'=>'');
    	if ($flag > 0) {
    		$data['flag'] = 1;
    		$data['msg'] = L('_add_success_');
    	}
    	echo json_encode($data);
    }


   
}